﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using BoardPACDSWS.General.Logs;
using BoardPACUtil.Util;
using BoardPACDSDAO.UserMgt;

namespace BoardPACDSWS.UserMgt
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "UserMgtService" in code, svc and config file together.
    public class UserMgtService : IUserMgtService
    {
        public string GetUserDisplayName(string userName)
        {
            try
            {
                Logs.EventLogger.Log("0," + LogPoint.Entry.ToString() + "," + Utility.GetAction(OperationContext.Current.IncomingMessageHeaders.Action) + "," + Global.UserName + ",Params(userName=" + userName + ")");
                UserDAO userDAO = new UserDAO();
                string output = userDAO.GetUserDisplayName(userName);
                Logs.EventLogger.Log("0," + LogPoint.Success.ToString() + "," + Utility.GetAction(OperationContext.Current.IncomingMessageHeaders.Action) + "," + Global.UserName + ",Params(userName=" + userName + ")");
                return output;
            }
            catch (GenServiceException e)
            {
                Logs.ErrorLogger.Log(e.Code + "," + LogPoint.Failure.ToString() + "," + Utility.GetAction(OperationContext.Current.IncomingMessageHeaders.Action) + "," + Global.UserName + ",Params(userName=" + userName + ")", e);
                throw new FaultException<GenFault>(new GenFault(e.Code), new FaultReason(e.Code));
            }
            catch (Exception e)
            {
                Logs.ErrorLogger.Log("err_717," + LogPoint.Failure.ToString() + "," + Utility.GetAction(OperationContext.Current.IncomingMessageHeaders.Action) + "," + Global.UserName + ",Params(userName=" + userName + ")", e);
                throw new FaultException<GenFault>(new GenFault("err_717"), new FaultReason("err_717"));
            }
        }
        
        public int GetUserCustomId(string userName)
        {
            try
            {
                Logs.EventLogger.Log("0," + LogPoint.Entry.ToString() + "," + Utility.GetAction(OperationContext.Current.IncomingMessageHeaders.Action) + "," + Global.UserName + ",Params(userName=" + userName + ")");
                UserDAO userDAO = new UserDAO();
                int output = userDAO.GetUserCustomIdDAO(userName);
                Logs.EventLogger.Log("0," + LogPoint.Success.ToString() + "," + Utility.GetAction(OperationContext.Current.IncomingMessageHeaders.Action) + "," + Global.UserName + ",Params(userName=" + userName + ")");
                return output;
            }
            catch (GenServiceException e)
            {
                Logs.ErrorLogger.Log(e.Code + "," + LogPoint.Failure.ToString() + "," + Utility.GetAction(OperationContext.Current.IncomingMessageHeaders.Action) + "," + Global.UserName + ",Params(userName=" + userName + ")", e);
                throw new FaultException<GenFault>(new GenFault(e.Code), new FaultReason(e.Code));
            }
            catch (Exception e)
            {
                Logs.ErrorLogger.Log("err_717," + LogPoint.Failure.ToString() + "," + Utility.GetAction(OperationContext.Current.IncomingMessageHeaders.Action) + "," + Global.UserName + ",Params(userName=" + userName + ")", e);
                throw new FaultException<GenFault>(new GenFault("err_717"), new FaultReason("err_717"));
            }
        }
    }
}
